import { Button, ButtonProps } from 'antd';
import React from 'react';
import styled from 'styled-components';

interface StyledButtonProps {
  hasIconAndLabel?: boolean;
  horizontal?: boolean;
  highlight?: boolean;
}

export const StyledButton = styled(
  React.forwardRef<HTMLButtonElement, StyledButtonProps & ButtonProps>(
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    ({ hasIconAndLabel, horizontal, highlight, ...restProps }, ref) => (
      <Button
        ref={ref}
        {...restProps}
        type='default'
      />
    ),
  ),
)<StyledButtonProps>`
  display: flex;
  flex-direction: ${({ horizontal }) => (horizontal ? 'row' : 'column')};
  align-items: center;
  justify-content: center;
  padding: 10px;
  height: ${({ hasIconAndLabel, horizontal }) =>
    hasIconAndLabel && !horizontal ? '48px' : '36px'};
  background-color: ${({ highlight }) => (highlight ? '#E2E4E6' : 'auto')};
  box-shadow: none;
  border: none !important;
  font-size: 12px;
  gap: ${({ hasIconAndLabel, horizontal }) =>
    hasIconAndLabel && !horizontal ? '0' : '8px'};

  &:hover {
    background-color: #f1f3f5 !important;
  }

  &:disabled {
    background-color: transparent;
  }
`;

export const StyledTabs = styled.div`
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 200px;

  > ul {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
    margin-bottom: -1px;
    list-style: none;
    border: 1px solid #e5e5e5;
    border-radius: 5px 5px 0 0;
    font-size: 13px;
    background-color: #f1f1f1;
    user-select: none;
    pointer-events: all;

    > li {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      padding: 8px 16px;
      cursor: pointer;

      &:last-child {
        border-radius: 0 5px 0 0;
      }

      &:first-child {
        border-radius: 5px 0 0 0;
      }

      /* &:nth-child(1) {
        border-radius: 5px 5px 0 0;
      } */

      &.active {
        background-color: #ffffff;
      }

      > i {
        &.freeze {
          width: 0;
          height: 0;
          border-top: 12px solid rgb(70 70 129); /* 调整三角形的大小 */
          border-right: 12px solid transparent; /* 右边透明 */
          position: absolute;
          top: 0;
          left: 0;
        }

        &.rounded {
          border-top-left-radius: 5px;
        }
      }
    }
  }
`;

export const StyledTabPanel = styled.div`
  background-color: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 10px 10px 0 0;
  min-width: 450px;
  min-height: 65px; // Prevent layout flashing when switching between tabs with/without the horizontal scrollbar
  padding: 5px 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  max-width: 100%;
  pointer-events: all;

  &::-webkit-scrollbar {
    height: 5px;
  }

  > div {
    position: relative;
    display: flex;
  }

  > div::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    right: 0;
    width: 1px;
    background-color: #ccc;
  }

  > div:last-child::after,
  > div:first-child::after {
    display: none;
  }
`;

export const StyledUpTabs = styled.div`
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;

  > ul {
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    margin: 0;
    padding: 0;
    margin-bottom: -1px;
    list-style: none;
    font-size: 13px;
    background-color: #f5f5f5;
    user-select: none;
    pointer-events: all;

    > li {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 58px;
      height: 100%;
      padding: 8px 16px;
      cursor: pointer;

      &.active {
        border-bottom: solid 3px blue;
      }
    }
  }
`;

export const StyledUpTabPanel = styled.div`
  background-color: #f5f5f5;
  min-width: 100%;
  min-height: 60px;
  padding: 5px 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  max-width: 90vw;
  pointer-events: all;

  &::-webkit-scrollbar {
    height: 5px;
  }

  > div {
    position: relative;
    display: flex;

    > button {
      background-color: #f5f5f5;
    }

    > div {
      background-color: #f5f5f5;

      > button {
        background-color: #f5f5f5;
      }
    }
  }

  > div::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    right: 0;
    width: 1px;
    background-color: #ccc;
  }

  > div:last-child::after,
  > div:first-child::after {
    display: none;
  }
`;
